package com.fsnbigdata.util;

/**
 * @author cqz
 * @title: CheckPasswdByRegex
 * @projectName fsnbigdata
 * @description: TODO
 * @date 2019/3/2017:37
 */
public class CheckPasswdByRegex {
    public static String checkPassword(String passwordStr) {
        if (passwordStr != null && !"".equals(passwordStr) && (passwordStr.length() < 8 || passwordStr.length() > 20)) {
            return "密码为(8-20)位字母、数字或英文字符!";
        }
        // Z = 字母,S = 数字,T = 特殊字符
        String regexZ = "[A-Za-z]+";
        String regexS = "^\\d+$";
        String regexT = "[~!@#$%^&*.]+";
        String regexZT = "[a-zA-Z~!@#$%^&*.]+";
        String regexZS = "[0-9A-Za-z]+";
        String regexST = "[\\d~!@#$%^&*.]*";
        String regexZST = "[\\da-zA-Z~!@#$%^&*.]+";
        if (passwordStr.matches(regexZ)){
            return "纯字母，弱";
        }
        if (passwordStr.matches(regexS)){
            return "纯数字，弱";
        }
        if (passwordStr.matches(regexT)){
            return "纯字符，弱";
        }
        if (passwordStr.matches(regexZT)){
            return "字母字符，中";
        }
        if (passwordStr.matches(regexZS)){
            return "字母数字，中";
        }
        if (passwordStr.matches(regexST)){
            return "数字字符，中";
        }
        if (passwordStr.matches(regexZST)) {
            //密码强度强
            return "1";
        }
        return "error";
    }
}
